{extend name="../application/index/view/index/base.html" /}

{block name="main-content"}
<!-- 导航栏开始 -->
<div class="breadcrumbs" id="breadcrumbs">
	<script type="text/javascript">
        try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
	</script>

	<ul class="breadcrumb">
		<li>
			<i class="icon-home home-icon"></i>
			<a href="#">权限控制</a>
		</li>
		<li class="active">权限管理</li>
	</ul><!-- .breadcrumb -->

	<div class="nav-search" id="nav-search">
		<form class="form-search">
									<span class="input-icon">
										<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
										<i class="icon-search nav-search-icon"></i>
									</span>
		</form>
	</div><!-- #nav-search -->
</div>
<!-- 导航栏结束 -->
<div style="margin: 15px;">
	<button class="btn btn-success" style="margin-bottom: 15px;" onclick="add()">
		<i class="icon-edit"></i>
		添加权限
	</button>

	<div class="tab-pane fade in active" id="home">
		<table class="table table-striped table-bordered table-hover table-condensed">
			<tr>
				<th>权限名</th>
				<th>权限</th>
				<th>操作</th>
			</tr>
			{volist name="data" id="v"}
			<tr>
				<td>{$v['_name']}</td>
				<td>{$v['name']}</td>
				<td>
					<a href="javascript:;" ruleId="{$v['id']}" onclick="add_child(this)">添加子权限</a> |
					<a href="javascript:;" ruleId="{$v['id']}" ruleName="{$v['name']}" ruleTitle="{$v['title']}" onclick="edit(this)">修改</a> |
					<a href="javascript:" onclick="delete_child(this)" ruleId="{$v['id']}">删除</a>
				</td>
			</tr>
			{/volist}
		</table>
	</div>

</div>

<!-- 添加菜单模态框开始 -->
<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title">
					添加权限
				</h4>
			</div>
			<div class="modal-body">
				<form class="form-inline" action="/index.php/index/auth/add" method="post">
					<input type="hidden" name="pid" value="0">
					<table class="table table-striped table-bordered table-hover table-condensed">
						<tr>
							<th width="12%">权限名：</th>
							<td>
								<input class="form-control" type="text" name="title">
							</td>
						</tr>
						<tr>
							<th>权限：</th>
							<td>
								<input class="form-control" type="text" name="name"> 输入模块/控制器/方法即可 例如 Admin/Rule/index
							</td>
						</tr>
						<tr>
							<th></th>
							<td>
								<input class="btn btn-success" type="submit" value="添加">
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
</div>
<!-- 添加菜单模态框结束 -->

<!-- 修改菜单模态框开始 -->
<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title">
					修改权限
				</h4>
			</div>
			<div class="modal-body">
				<form  class="form-inline" action="/index.php/index/auth/edit" method="post">
					<input type="hidden" name="id">
					<table class="table table-striped table-bordered table-hover table-condensed">
						<tr>
							<th width="12%">权限名：</th>
							<td>
								<input class="form-control" type="text" name="title">
							</td>
						</tr>
						<tr>
							<th>权限：</th>
							<td>
								<input class="form-control" type="text" name="name"> 输入模块/控制器/方法即可 例如 Admin/Rule/index
							</td>
						</tr>
						<tr>
							<th></th>
							<td>
								<input class="btn btn-success" type="submit" value="修改">
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
</div>
<!-- 修改菜单模态框结束 -->
<bootstrapjs />
<script>
    // 添加菜单
    function add(){
        $("input[name='title'],input[name='name']").val('');
        $("input[name='pid']").val(0);
        $('#bjy-add').modal('show');
    }

    // 添加子菜单
    function add_child(obj){
        var ruleId=$(obj).attr('ruleId');
        $("input[name='pid']").val(ruleId);
        $("input[name='title']").val('');
        $("input[name='name']").val('');
        $('#bjy-add').modal('show');
    }

    // 修改菜单
    function edit(obj){
        var ruleId=$(obj).attr('ruleId');
        var ruletitle=$(obj).attr('ruletitle');
        var ruleName=$(obj).attr('ruleName');
        $("input[name='id']").val(ruleId);
        $("input[name='title']").val(ruletitle);
        $("input[name='name']").val(ruleName);
        $('#bjy-edit').modal('show');
    }

    // 删除菜单
    function delete_child(obj){
        var ruleId=$(obj).attr('ruleId');
		$.get('/index.php/index/auth/delete',{"id":ruleId},function (ret) {
			if(ret.code == 200){
                layer.msg('删除成功');
                location.reload();
			}else{
                layer.msg('删除失败');
			}
        });
    }
</script>
{/block}
